-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for gRPC Server Response Headers and Trailers, adding ClientAfter handler #479
Merged
+654
−63
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
basvanbeek
changed the title
[WIP]: grpc ClientAfter handler and multiple calls to Client Before/After funcs.
grpc ClientAfter handler and multiple calls to Client Before/After funcs.
Mar 4, 2017
basvanbeek
changed the title
grpc ClientAfter handler and multiple calls to Client Before/After funcs.
WIP: grpc ClientAfter handler and multiple calls to Client Before/After funcs.
Mar 5, 2017
basvanbeek
changed the title
WIP: grpc ClientAfter handler and multiple calls to Client Before/After funcs.
grpc ClientAfter handler and multiple calls to Client Before/After funcs.
Mar 5, 2017
basvanbeek
changed the title
grpc ClientAfter handler and multiple calls to Client Before/After funcs.
Support for gRPC Server Response Headers and Trailers, adding ClientAfter handler
Mar 5, 2017
peterbourgon
reviewed
Mar 5, 2017
@@ -222,7 +222,7 @@ func main() { | |||
return | |||
} | |||
|
|||
srv := addsvc.MakeGRPCServer(ctx, endpoints, tracer, logger) | |||
srv := addsvc.MakeGRPCServer(endpoints, tracer, logger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
Yep, this all scans perfectly, LGTM. In the merge commit, would you mind adding a small sentence or two about the changes required for consumers? |
will do |
- Separated ClientRequestFunc and ServerRequestFunc to highlight that request metadata in a ServerRequestFunc is supposed to be immutable. - Return context in ServerResponseFuncs like with the HTTP transport, to allow passing data between chained serverAfter middlewares and finally to the encoding step so it can be used to alter the response payload prior to sending this response to the client.
jamesgist
pushed a commit
to jamesgist/kit
that referenced
this pull request
Nov 1, 2024
Improved gRPC transport with some minor breaking changes. gRPC Server Transport ===================== Existing customers of the gRPC Server transport will have to get rid of the service scoped context as this has become kind of an anti-pattern. This changes the gRPC server construction signature from: NewServer(ctx, endpoint, decoder, encoder, ...serverOptions) to: NewServer(endpoint, decoder, encoder, ...serverOptions) Server customers using `ResponseFunc` will need to update their signatures from: ResponseFunc func(context.Context, *metadata.MD) to: ServerResponseFunc func(ctx context.Context, header *metadata.MD, trailer *metadata.MD) context.Context PLEASE NOTE! Next to this signature update it might be that certain logic needs to move to the ServerRequestFunc if the logic was reading metadata from the originating request. This was incorrect behavior anyway as this is what ServerRequestFuncs are intended to handle. Use context to pass details if needing to manipulate response data based on incoming request metadata. gRPC Client Transport ===================== Customers of the gRPC Client transport will benefit from the newly added ClientResponseFunc, which will allow them to pick up metadata from both Headers and Trailers returned by a gRPC Server. Consumers referencing RequestFunc will need to rename to ClientRequestFunc due to RequestFunc having been split up for Client and Server side. ServerBefore() and ServerAfter() now append the referenced functions so next to variadic function parameters you can also call ServerBefore() and ServerAfter() multiple times without overwriting previous invocations. This is in line with the same change that already occurred server side. Context ======= Similar to the HTTP Server and Client Transport, the gRPC Server and Client Transport now feature passing of context.Context for all Before and After Funcs. This can be helpful if needing to pass data along to chained middlewares or when response header logic might need to signal changes needed in the regular response payload which now can be done by passing details in context and picking them up in the response encoder step.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a (minor) breaking change to the existing gRPC transport but imho is a better and more Go kit idiomatic approach to handling server response metadata.
Stuff changed:
context
as it purely uses the per request context as provided by gRPC-changed ServerResponseFunc to provide you with empty header and trailer metadata pointers so you can fill them with chained middlewares